<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="com.carmanage.domain.Page"%>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script type="text/javascript" src="plugins/jQuery/jQuery-2.2.0.min.js"></script>

<title>角色管理</title>

<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
<!-- Bootstrap 3.3.6 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet"
	href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet"
	href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/dist/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/dist/css/skins/_all-skins.min.css">
<!-- iCheck -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/iCheck/flat/blue.css">
<!-- Morris chart -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/morris/morris.css">
<!-- jvectormap -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
<!-- Date Picker -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/datepicker/datepicker3.css">
<!-- Daterange picker -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker-bs3.css">
<!-- bootstrap wysihtml5 - text editor -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/dist/css/theme.css"
	media="all">
<style type="text/css">
label {
	font-weight: normal;
}

.choice {
	margin-left: 15px;
	margin-bottom: 12px;
}

.choice label {
	margin-left: 14px;
}
</style>
</head>

<body class="hold-transition skin-blue sidebar-mini"
	style="font-family:Microsoft YaHei;">
	<div class="wrapper">

		<header class="main-header">
			<!-- Logo -->
			<div class="logo" style="background-color:#ec7500;">
				<!-- logo for regular state and mobile devices -->
				<span class="logo-lg"><b
					style="font-size:18px;margin-left:-40px ">厂车管理系统</b> </span>
			</div>
			<!-- Header Navbar: style can be found in header.less -->
			<nav class="navbar navbar-static-top"
				style="background-color:#ec7500;">
				<!-- Sidebar toggle button-->
				<a href="#" class="sidebar-toggle" data-toggle="offcanvas"
					role="button"> <span class="sr-only">Toggle navigation</span> </a>

				<div class="navbar-custom-menu">
					<ul class="nav navbar-nav">
						<!-- User Account:-->
						<li class="dropdown user user-menu"><span class="hidden-xs"></span>
						</li>
						<li style="color:#ffffff; background:#959595;padding:15px">${sessionScope.CurrentUser.username}</li>
						<li><a><i class="fa fa-sign-out"></i> </a></li>
					</ul>
				</div>
			</nav>
		</header>
		<!-- Left side column. contains the logo and sidebar -->
		<aside class="main-sidebar">
			<!-- sidebar: style can be found in sidebar.less -->
		<section class="sidebar"> <!-- sidebar menu: : style can be found in sidebar.less -->
		<ul class="sidebar-menu">
		<c:forEach var = "UserRoleActionsId"  items = "${sessionScope.CurrentUserActionsId}">
		  <c:choose>
		    <c:when test ="${UserRoleActionsId == 4 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/showEmps.do"> <i
					class="fa fa-user"></i><span>员工管理</span>
					 </a></li>
					 </c:when>
					 <c:when test ="${UserRoleActionsId == 8 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/showBuses.do"> <i class="fa fa-bus"></i>
					<span>车辆管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 12 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/carschedule_all.do"> <i class="fa fa-calendar"></i>
					<span>排班管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 16 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/pages/stationManage.jsp"> <i
					class="fa fa-map-marker"></i> <span>站点管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 20 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/pages/lineManage.jsp"> <i class="fa fa-road"></i>
					<span>线路管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 24 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/findUserFirstPage.do"> <i class="fa fa-user-plus"></i>
					<span>用户管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 28 }">
			<li class="active treeview"><a href="${pageContext.request.contextPath}/findRoleFirstPage.do"> <i
					class="fa fa-check-square-o"></i> <span>角色管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 32 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/pages/dataSave.jsp"> <i class="fa fa-save"></i>
					<span>数据备份</span> </a></li>
					</c:when>
					</c:choose></c:forEach>
		</ul>
		</section> <!-- /.sidebar --> </aside>

			<!-- /.sidebar -->
		</aside>

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper" style="background-color:#f2f2f2;">
			<!-- Main content -->
			<section class="content">

				<form class="navbar-form navbar-left" role="search">
					<div class="form-group">
						<input type="text" class="form-control" id="navbar-search-input"
							placeholder="输入姓名"
							style="width:110px; margin-left:-5px;color:#ffffff;"> <input
							type="text" class="form-control" id="navbar-search-input"
							placeholder="输入工号" style="width:185px;margin-left:-2px;">
					</div>
					<button class="btn btn-info" name="query" onclick="func()"
						style="background:none;border:none;">
						<i class="fa   fa-search" style="color:#ff9900;"></i>
					</button>
					<a style="padding:0px 15px;margin-top:10px;cursor:pointer;"
						data-toggle="modal" data-target="#myModal"> <i
						class="fa  fa-plus-square" style="color:#ff9900;"></i>&nbsp;增加角色 </a>
				</form>
				<div class="box">
					<!-- /.box-header -->
					<div class="box-body"
						style="padding-top:2px;margin:margin-top:-4px;">
						<table class="table table-bordered table-striped">
							<tr>
							    <th style="width:30px;text-align:center;"></th>
								<th style="width:55px;text-align:center;">角色编号</th>
								<th style="width:40px;text-align:center;">角色名称</th>
								<th style="width:55px;text-align:center;">角色创建日期</th>
								<th style="width:55px;text-align:center;">操作</th>
							</tr>
				        <% 
				           Page RolePage = (Page) session.getAttribute("RolePage");
                           int k = RolePage.getPageStartRow();
                        %>
				    
							<c:forEach var="Role" items = "${requestScope.RolesByPage}">
							<tr>
								<td><%=++k%></td>
								<td>${Role.roleid}</td>
								<td>${Role.rolename}</td>
								<td>${Role.creatdate}</td>
								
								<td style="text-align:center;">
								<c:forEach var = "actionId" items = "${sessionScope.CurrentUserActionsId}">
								    <c:if test="${actionId == 26 }"> 
										<i class="fa  fa-trash" style="color:#ff9900;cursor:pointer;" ></i>&nbsp;&nbsp;&nbsp;
								   </c:if>
								    
								   <c:if test="${actionId == 27 }"> 
								   <a href="#"
										data-toggle="modal" data-target="#u01"
										> 
									    <i class="fa  fa-edit" style="color:#ff9900;margin:0px 15px 0 -10px;cursor:pointer;" onclick="updateRole('${Role.roleid}');document.UpdateRoleForm.rolename.value='${Role.rolename}';document.UpdateRoleForm.roleid.value='${Role.roleid}'">
									   </i> </a>
								     </c:if>
								   
								</c:forEach>
								</td>
							</tr>
						  </c:forEach>
						</table>
					</div>
					<!-- /.box-body -->
					<div class="box-footer clearfix">
						<ul class="pagination pagination-sm no-margin pull-right">
								<c:choose>
         <c:when test="${RolePage.currentPage == 1 }">
            <li><a>首页</a></li>
            <li><a href="#">&laquo;</a></li>
         </c:when>
         <c:otherwise>
            <li><a href="${pageContext.request.contextPath}/findRolePageBy.do?currentPage=1">首页</a></li>
            <li><a href="${pageContext.request.contextPath}/findRolePageBy.do?currentPage=${RolePage.previousPage}">&laquo;</a></li>
         </c:otherwise>
         </c:choose>
            <li><a href="#">${RolePage.currentPage}</a></li>
         	<c:choose>
         <c:when test="${RolePage.currentPage >= RolePage.totalPages }">
            <li><a href="#">&raquo;</a></li>
            <li><a href="#">尾页</a></li>
         </c:when>
         <c:otherwise>
            <li><a href="${pageContext.request.contextPath}/findRolePageBy.do?currentPage=${RolePage.nextPage}">&raquo;</a></li>
            <li><a href="${pageContext.request.contextPath}/findRolePageBy.do?currentPage=${RolePage.totalPages}">尾页</a></li>
         </c:otherwise>
         </c:choose>
	</ul>
</div>
</div>
				<!-- add -->
				<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
					aria-labelledby="myModalLabel" aria-hidden="true" style="visibility: none;">
					<div class="modal-dialog">
						<div class="modal-content"
							style="width:400px;height:470px;position:relative; top:50px;left:100px;">
							<div class="modal-header"
								style="color:#ffffff;background:#ff9900;">
								<button type="button" class="close" data-dismiss="modal"
									aria-hidden="true">
									<i class="fa  fa-close " style="color:#ffffff"></i>
								</button>
								<h4 class="modal-title" id="myModalLabel">添加角色</h4>
							</div>
							<div class="modal-body">
								<form class="form-horizontal" role="form" name = "AddRoleForm">
									<div class="form-group" style="margin-left:30px;">
										<label for="lastname" class="col-sm-2 control-label">角色名称</label>
										<div class="col-sm-8">
											<input type="text" name = "rolename" class="form-control" id="lastname"
												style="background:none;color:#000000;border:1px solid #bcbcbc;"
												placeholder="请输入角色名称">
										</div>
										   <%  
										    Date date = new Date();
								
										   %>
										<input type="hidden" value="<%=date%>" name = "creatdate">
									</div>
								</form>
							</div>
							<div class="modal-footer" style="padding:0 30%;">
								<button type="submit" class="btn btn-default"
									style="color:#ffffff;background:#ff9900;" onclick = "saveRole()">保&nbsp;存</button>
								<button type="button" class="btn btn-default"
									data-dismiss="modal" style="color:#ffffff;background:#a0a0a0;">取&nbsp;消
								</button>
							</div>
						</div>
						<!-- /.modal-content -->
					</div>
					<!-- /.modal -->
				</div>
				<div id="u01" class="modal fade" style="display:none;">
					<div class="modal-dialog">
						<div class="modal-content"
							style="width:400px;height:520px;position:relative; top:50px;left:100px;">
							<div class="modal-header"
								style="color:#ffffff;background:#ff9900;">
								<button type="button" class="close" data-dismiss="modal"
									aria-hidden="true">
									<i class="fa  fa-close " style="color:#ffffff"></i>
								</button>
								<h4 class="modal-title" id="myModalLabel">修改角色</h4>
							</div>
							<div class="modal-body">
							<form name = "UpdateRoleForm">
								<div style="margin-bottom:30px;">
									    	<input type="text"  value="输入名字" class="form-control" name = "rolename"
											id="navbar-search-input"
											style=";color:#666; width:200px; margin-left:50px;border:1px solid #ff9900; background:none;"/>
						           		    <input type ="hidden" name = "roleid" value = ""/>
								</div>
                                  
									<div class="choice">
										<label>员工管理</label> 
										    <label><input onclick="change(1)" name = "ActionsId" id="1"  type="checkbox" value="1" />增加 </label> 
											<label><input onclick="change(2)" name = "ActionsId" id="2"  type="checkbox" value="2" />删除 </label> 
											<label><input onclick="change(3)" name = "ActionsId" id="3"  type="checkbox" value="3" />修改 </label> 
											<label><input onclick="change(4)" name = "ActionsId" id="4"  type="checkbox" value="4" />查询</label>
									</div>
									<div class="choice">
										<label>车辆管理</label> 
										    <label><input onclick="change(5)"name = "ActionsId" id="5"  type="checkbox" value="5" />增加 </label> 
											<label><input onclick="change(6)"name = "ActionsId" id="6"  type="checkbox" value="6" />删除 </label> 
											<label><input onclick="change(7)"name = "ActionsId" id="7"  type="checkbox" value="7" />修改 </label> 
											<label><input onclick="change(8)" name = "ActionsId" id="8"  type="checkbox" value="8" />查询</label>
									</div>
									<div class="choice">
										<label>排班管理</label> 
							                <label><input onclick="change(9) "name = "ActionsId" id="9"  type="checkbox" value="9" />增加 </label> 
											<label><input onclick="change(10)"name = "ActionsId" id="10"  type="checkbox" value="10" />删除 </label> 
											<label><input onclick="change(11)"name = "ActionsId" id="11"  type="checkbox" value="11" />修改 </label> 
											<label><input onclick="change(12)"name = "ActionsId" id="12"  type="checkbox" value="12" />查询</label>
									</div>
									<div class="choice">
										<label>站点管理</label> 
								            <label><input onclick="change(13)" name = "ActionsId" id="13"  type="checkbox" value="13" />增加 </label> 
											<label><input onclick="change(14)" name = "ActionsId" id="14"  type="checkbox" value="14" />删除 </label> 
											<label><input onclick="change(15)" name = "ActionsId" id="15"  type="checkbox" value="15" />修改 </label> 
											<label><input onclick="change(16)" name = "ActionsId" id="16"  type="checkbox" value="16" />查询</label>
									</div>
									<div class="choice">
										<label>线路管理</label>
									        <label><input onclick="change(17)" name = "ActionsId" id="17"  type="checkbox" value="17" />增加 </label> 
											<label><input onclick="change(18)" name = "ActionsId" id="18"  type="checkbox" value="18" />删除 </label> 
											<label><input onclick="change(19)" name = "ActionsId" id="19"  type="checkbox" value="19" />修改 </label> 
											<label><input onclick="change(20)" name = "ActionsId" id="20"  type="checkbox" value="20" />查询</label>
									</div>
									<div class="choice">
										<label>用户管理</label> 
									        <label><input onclick="change(21)"name = "ActionsId" id="21"  type="checkbox" value="21" />增加 </label> 
											<label><input onclick="change(22)"name = "ActionsId" id="22"  type="checkbox" value="22" />删除 </label> 
											<label><input onclick="change(23)"name = "ActionsId" id="23"  type="checkbox" value="23" />修改 </label> 
											<label><input onclick="change(24)"name = "ActionsId" id="24"  type="checkbox" value="24" />查询</label>
									</div>
									<div class="choice">
										<label>角色管理</label> 
											<label><input onclick="change(25)"name = "ActionsId" id="25"  type="checkbox" value="25" />增加 </label> 
											<label><input onclick="change(26)"name = "ActionsId" id="26"  type="checkbox" value="26" />删除 </label> 
											<label><input onclick="change(27)"name = "ActionsId" id="27"  type="checkbox" value="27" />修改 </label> 
											<label><input onclick="change(28)"name = "ActionsId" id="28"  type="checkbox" value="28" />查询</label>
									</div>
									<div class="choice">
										<label>数据备份</label> 
											<label><input onclick="change(29)" name = "ActionsId" id="29"  type="checkbox" value="29" />增加 </label> 
											<label><input onclick="change(30)" name = "ActionsId" id="30"  type="checkbox" value="30" />删除 </label> 
											<label><input onclick="change(31)" name = "ActionsId" id="31"  type="checkbox" value="31" />修改 </label> 
											<label><input onclick="change(32)" name = "ActionsId" id="32"  type="checkbox" value="32" />查询</label>
									</div>



									<div class="modal-footer" style="padding:0 30%;">
									
										<button type="button"  onclick="AfterUpdate()" class="btn btn-default"
											style="color:#ffffff;background:#ff9900; margin-top:20px;margin-right:10px;">保&nbsp;存</button>
										<button type="button" class="btn btn-default"
											data-dismiss="modal"
											style="color:#ffffff;background:#a0a0a0;margin-top:20px;">取&nbsp;消
										</button>
									</div>
								</form>
							</div>
							<!-- /.modal-content -->
						</div>
						<!-- /.modal -->
					</div>
				</div>
			</section>
			<!-- /.content -->
		</div>
		<!-- /.content-wrapper -->

		<!-- ./wrapper -->

		<!-- jQuery 2.2.0 -->
		<script
			src="${pageContext.request.contextPath}/plugins/jQuery/jQuery-2.2.0.min.js"></script>
		<!-- jQuery UI 1.11.4 -->
		<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
		<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
		<script>
			$.widget.bridge('uibutton', $.ui.button);
		</script>
		<!-- Bootstrap 3.3.6 -->
		<script
			src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
		<!-- Morris.js charts -->
		<script
			src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
		<script
			src="${pageContext.request.contextPath}/plugins/morris/morris.min.js"></script>
		<!-- Sparkline -->
		<script
			src="${pageContext.request.contextPath}/plugins/sparkline/jquery.sparkline.min.js"></script>
		<!-- jvectormap -->
		<script
			src="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
		<script
			src="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
		<!-- jQuery Knob Chart -->
		<script
			src="${pageContext.request.contextPath}/plugins/knob/jquery.knob.js"></script>
		<!-- daterangepicker -->
		<script
			src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
		<script
			src="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker.js"></script>
		<!-- datepicker -->
		<script
			src="${pageContext.request.contextPath}/plugins/datepicker/bootstrap-datepicker.js"></script>
		<!-- Bootstrap WYSIHTML5 -->
		<script
			src="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
		<!-- Slimscroll -->
		<script
			src="${pageContext.request.contextPath}/plugins/slimScroll/jquery.slimscroll.min.js"></script>
		<!-- FastClick -->
		<script
			src="${pageContext.request.contextPath}/plugins/fastclick/fastclick.js"></script>
		<!-- AdminLTE App -->
		<script src="${pageContext.request.contextPath}/dist/js/app.min.js"></script>
		<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
		<script
			src="${pageContext.request.contextPath}/dist/js/pages/dashboard.js"></script>
		<!-- AdminLTE for demo purposes -->
		<script src="${pageContext.request.contextPath}/dist/js/demo.js"></script>
		<script src="${pageContext.request.contextPath}/dist/js/jquery.min.js"></script>
</body>
</html>

<script type = "text/javascript">
    function updateRole(roleid){ 
      var i = 1;
      for(i;i<=32;i++){
         document.getElementById(i).checked = false;
      }
         $.ajax({
			type:"POST",
			url:"${pageContext.request.contextPath}/findActionsIdByRoleId.do?roleid="+roleid,
			success:function(message,status){
				if(status == "success"){
					var ActionsIdList = message;
					setActionIdMessage(ActionsIdList);
					
				}
			}
		})
    }
    
    
    function setActionIdMessage(ActionsIdList){

          for(var i = 0;i<ActionsIdList.length;i++){
              var actionId = ActionsIdList[i];
              document.getElementById(actionId).checked = true;
             
          }
    }
    
    function saveRole(){
         var rolename = document.AddRoleForm.rolename.value;
         var creatdate = document.AddRoleForm.creatdate.value;
         $.ajax({
			type:"POST",
			url:"${pageContext.request.contextPath}/addRole.do?rolename="+rolename+"&creatdate="+creatdate,
			success:function(message,status){
				if(status == "success"){
					var addRoleResult = message;
					if(addRoleResult == 1){
					   alert("角色添加成功！");
					   window.location.href = "/CarManage/findRoleFirstPage.do";
					}
					else
					   alert("角色添加失败！");
				}
			}
		})
    }
    
  
</script>

<script type = "text/javascript">
 
	function AfterUpdate() {
		
		var roleid = document.UpdateRoleForm.roleid.value;
		var actionsid = document.UpdateRoleForm.ActionsId;
		var actions = "";
		var max = actionsid.length;
		for (var i = 0; i < max; i++) {
			if (actionsid[i].checked == true) {
				actions = actions + actionsid[i].value  +  "a";
			}
		}

		$.ajax({
					type : "POST",
					data : "actions=" + actions + "&roleid=" + roleid,
					url : "${pageContext.request.contextPath}/updateRole.do",
					success : function(message, status) {
						if (status == "success") {
							var addRoleResult = message;
							if (addRoleResult == 1) {
								alert("角色修改成功！");
								window.location.href = "/CarManage/findRoleFirstPage.do";
							} else
								alert("角色添加失败！");
						}
					}
				});
	}
</script>
<script type="text/javascript">
    function chang(id){
       var box = document.getElementById(id);
       if(box.checked){
          box.checked = false;
       }else
       {
          box.checked = true;
       }
    
    }

</script>
